package com.bilibili.sys.service.impl;

import com.bilibili.sys.bean.SysRole;
import com.bilibili.sys.bean.SysUser;
import com.bilibili.sys.dao.IRoleDao;
import com.bilibili.sys.dao.impl.RoleDaoImpl;
import com.bilibili.sys.service.IRoleService;
import com.bilibili.sys.service.IUserService;
import com.bilibili.sys.utils.PageUtils;

import java.util.List;

/**
 * @author alpha
 * @program: BookSystem
 * @description:
 * @since 2024-03-28 08:31
 **/

public class RoleServiceImpl implements IRoleService {
    private IRoleDao dao = new RoleDaoImpl();
    private IUserService userService = new UserServiceImpl();
    @Override
    public List<SysRole> list(SysRole entity) {
        return dao.list(entity);
    }

    @Override
    public int save(SysRole entity) {
        return dao.save(entity);
    }

    @Override
    public SysRole findById(int id) {
        return dao.findById(id);
    }

    @Override
    public int updateById(SysRole entity) {
        return dao.updateById(entity);
    }

    @Override
    public int deleteById(int id) {
        return dao.deleteById(id);
    }

    @Override
    public void listPage(PageUtils pageUtils) {
        //查询分页的数据
        List<SysRole> list = dao.listPage(pageUtils);
        //查询满足条件的记录数
        int count = dao.count(pageUtils);
        //封装分页的数据
        pageUtils.setList(list);
        pageUtils.setTotalPage(count);

    }

    @Override
    public int count(PageUtils pageUtils) {
        return dao.count(pageUtils);
    }

    @Override
    public boolean checkRoleDispatch(int roleId) {
        SysUser entity = new SysUser();
        entity.setRoleId(roleId);
        //return userService.list(entity).size() == 0 ? true:false;
        return userService.list(entity).size() == 0 ? true : false;
    }


}
